import requests


def login_and_get_bookshelf(username, password):
    login_url = "https://passport.17k.com/ck/user/login"
    url = "https://user.17k.com/ck/author2/shelf?page=1&appKey=2406394919"
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36'}
    data = {
        "loginName": username,
        "password": password
    }
    session = requests.Session()
    session.post(url=login_url, headers=headers, data=data)
    bookshelf = session.get(url=url, headers=headers).json()
    book_names = []
    for book in bookshelf['data']:
        book_names.append(book['bookName'])
    return book_names


if __name__ == '__main__':
    username = "13503450662"
    password = "l27y92fcbv"
    bookshelf = login_and_get_bookshelf(username, password)

    # print(bookshelf)
    for book in bookshelf:
        print(book)
